move ([1, 2, 3]); goto([0, 0, 10]); goto([-, -, 10]); /* Move the Z-axis */
goto([0, 0]); /* Move XY-axes */ G1 X1.00000000 Y2.00000000 Z3.00000000
G0 X0.00000000 Y0.00000000 Z10.00000000
G0 Z10.00000000
G0 X0.00000000 Y0.00000000 SafeZ = [-, -, 10];
HomePos = [0, 0];
goto(SafeZ); /* Retract Z */
goto(HomePos); /* Back to home-base */
SafeZ = [-, -, 10];
CutZ = [-, -, -1];
HomePos = [0, 0];
Square = { [0, 0], [1, 0], [1, 1], [0, 1] };
goto(Square[3]); /* To last point */
move(CutZ); /* Goto cutting depth */
move(Square[0]); /* Cut the square */
move(Square[1]);
move(Square[2]);
move(Square[3]);
goto(SafeZ); /* Retract */
goto(HomePos); /* Back to home-base */
SafeZ = [-, -, 10.0mm];
CutZ = [-, -, -1.0mm];
HomePos = [0.0mm, 0.0mm];
Square = { [0, 0], [1, 0], [1, 1], [0, 1] };
Offset = [-2.0mm, 5.0mm];
Square = Square * 10.0in + Offset; /* Scale and move the square */
feedrate(100mm); /* Set feed so it can be visualized by LinuxCNC */
goto(Square[-1]); /* To last point */
move(CutZ); /* Goto cutting depth */
foreach(Square; v) {
move(v); /* Cut the square */
}
goto(SafeZ); /* Retract */
goto(HomePos); /* Back to home-base */ metric = 100mm;
imperial = 5in;
pcbmils = 400mil; /* converted to 0.4in */
degrees = 30deg;
radians = 3.14159265359rad; metric = 100mm;
imperial = 5in;
mi = metric + imperial; /* mi becomes metric float 227.0mm */
im = imperial + metric; /* im becomes imperial float 8.93700787402in */
i1 = 10;
i2 = 4;
divi = i1 / i2; /* divi becomes integer 2 */
fl = 4.0;
divf = i1 / fl; /* divf becomes float 2.5 */ SafeZ = [-, -, 10.0mm];
CutZ = [-, -, -1.0mm];
HomePos = [0.0mm, 0.0mm];
Square = { [0, 0], [1, 0], [1, 1], [0, 1] };
Offset = [-2.0mm, 5.0mm];
Square = Square * 10.0in + Offset; /* Scale and move the square */
feedrate(100mm); /* Set feed so it can be visualized by LinuxCNC */
goto(Square[-1]); /* To last point */
move(CutZ); /* Goto cutting depth */
foreach(Square; v) {
move(v); /* Cut the square */
}
goto(SafeZ); /* Retract */
goto(HomePos); /* Back to home-base */ F100.00000000
G0 X-2.00000000 Y259.00000000
G1 Z-1.00000000
G1 X-2.00000000 Y5.00000000
G1 X252.00000000 Y5.00000000
G1 X252.00000000 Y259.00000000
G1 X-2.00000000 Y259.00000000
G0 Z10.00000000
G0 X0.00000000 Y0.00000000
SafeZ = [-, -, 10.0mm];
CutZ = [-, -, -1.0mm];
HomePos = [0.0mm, 0.0mm];
Square = { [0, 0], [1, 0], [1, 1], [0, 1] };
function cut_the_path(path, offset)
{
path += offset; /* Move the path to the actual position */
goto(path[-1]); /* To last point */
move(CutZ); /* Goto cutting depth */
foreach(path; v) {
move(v); /* Cut the path */
}
goto(SafeZ); /* Retract */
}
feedrate(100mm); /* Set feed so it can be visualized by LinuxCNC */
goto(SafeZ); /* Initial to safe Z retraction point*/
cut_the_path(Square * 1in, [10.0mm, 5.0mm]); /* First square */
cut_the_path(Square * 2in, [15.0mm, 15.0mm]); /* Second square */
cut_the_path(Square * 3in, [20.0mm, 25.0mm]); /* Third square */
cut_the_path(Square * 4in, [25.0mm, 35.0mm]); /* Fourth square */
cut_the_path(Square * 5in, [30.0mm, 45.0mm]); /* Fifth square */
goto(HomePos); /* Back to home-base */ SafeZ = [-, -, 10.0mm];
CutZ = [-, -, -1.0mm];
HomePos = [0.0mm, 0.0mm];
Square = { [0, 0], [1, 0], [1, 1], [0, 1] };
function cut_the_path(path, offset)
{
path += offset; /* Move the path to the actual position */
goto(path[-1]); /* To last point */
move(CutZ); /* Goto cutting depth */
foreach(path; v) {
move(v); /* Cut the path */
}
goto(SafeZ); /* Retract */
}
feedrate(100mm); /* Set feed so it can be visualized by LinuxCNC */
goto(SafeZ); /* Initial to safe Z retraction point*/
repeat(5; i) {
cut_the_path(Square * (1.0in + i), [10.0mm, 5.0mm] + [5.0mm, 10.0mm] * i);
}
goto(HomePos); /* Back to home-base */ 1 / 10 → 0 // Integer result
1.0 / 10 → 0.1
1 / 10.0 → 0.1
1.0 / 10.0 → 0.1
1mm / 10 → 0mm // Integer result
1.0mm / 10 → 0.1mm
1mm + 1in → 26.4mm // Implicit conversion to floating point a = 0;
(a + 1.0e-12) == a // false
(a + 0.9e-12) == a // true a = 1.0;
to_int(1.0 + 0.9e-12); // 1 within EPSILON
to_int(1.0 - 0.9e-12); // 1 within EPSILON
to_int(1.0 + 1.0e-12); // 1 truncated
to_int(1.0 - 1.0e-12); // 0 truncated undefvar = [-][0];
undefvar = undef(); Exclusive Add (+),
left-hand side undef is retained, right-hand side undef substituded by 0
[15, -, -2] + [-, 10] is: → or:
[15, -, -2] [15, -, -2]
+ [ -, 10] + [ 0, 10, 0]
→
[15, -, -2] [15, -, -2]
Inclusive Add (+|),
both left- and right-hand side undef substituted by 0
[15, -, -2] +| [-, 10] is: → or:
[15, -, -2] [15, 0, -2]
+| [ -, 10] +| [ 0, 10, 0]
→
[15, 10, -2] [15, 10, -2]
Exclusive Subtract (-),
left-hand side undef is retained, right-hand side undef substituded by 0
[15, -, -2] - [-, 10] is: → or:
[15, -, -2] [15, -, -2]
- [ -, 10] - [ 0, 10, 0]
→
[15, -, -2] [15, -, -2]
Inclusive Subtract (-|),
both left- and right-hand side undef substituted by 0
[15, -, -2] -| [-, 10] is: → or:
[15, -, -2] [15, 0, -2]
-| [ -, 10] -| [ 0, 10, 0]
→
[15, -10, -2] [15, -10, -2] Exclusive Add (+),
left-hand side undef is retained, right-hand side undef substituded by 0
[-, 10] + [15, -, -2] is: → or:
[ -, 10] [ -, 10, -]
+ [15, -, -2] + [15, 0, -2]
→
[ -, 10, -] [ -, 10, -]
Inclusive Add (+|),
both left- and right-hand side undef substituted by 0
[-, 10] +| [15, -, -2] is: → or:
[ -, 10] [ 0, 10, 0]
+| [15, -, -2] +| [15, 0, -2]
→
[15, 10, -2] [15, 10, -2] val = (1<<2) | (1<<4); // val = 20 (0x14)
val = 0x5a & 0x0f; // val = 10 (0x0a)
val = ~1; // val = -2 (= -(1) - 1) [-, 2, 3] | [4, 5] → [4, 2, 3] // Note: [4, 5] equals [4, 5, -] in this context
[1, -, 3] | [4, 5] → [1, 5, 3]
[1, 2, -] | [4, 5] → [1, 2, -]
[-, 2, 3] & [4, 5] → [-, 5, 3]
[1, -, 3] & [4, 5] → [4, -, 3]
[1, 2, -] & [4, 5] → [4, 5, -] vector = [1, 2, 3];
vector[2] = 6; /* → [1, 2, 6] */
vector[3] = vector[-1]; /* → [1, 2, 6, 6] */
vector[7] = 2; /* → [1, 2, 6, 6, -, -, -, 2] */
vlist = {};
vlist[2] = [1, 2]; /* → { [], [], [1, 2] } */
vlist[1][3] = 3.1415; /* → { [], [-, -, -, 3.1415], [1, 2] } */
/* Rvalue may be constant expression */
myvec = {[1,2], [2,3]}[1]; /* → [2, 3] */
myval = [1, 2, 3][1]; /* → 2 */ vector = [1, 2, 3];
call_xy(vector.x, vector.y); /* Same as call_xy(vector[0], vector[1]); */
vector.z = 6; /* → [1, 2, 6] */
vector.a = vector[-1]; /* → [1, 2, 6, 6] */
vector.v = 2; /* → [1, 2, 6, 6, -, -, -, 2] */ 1 << 2 → 4
6 >> 1 → 3
[1, 2] << 1 → [2]
[1, 2] >> 2 → [-, -, 1, 2]
{[1,2], [3,4]} << 1 → {[3,4]}
{[1,2], [3,4]} >> 1 → {[], [1,2], [3,4]}
vnn = [2.0, 2.0];
vmm = [1.0mm, 2.0mm];
vin = [2.0in, 1.0in];
dotp = vnn * vnn; // 8.00000000
dotp = vnn * vmm; // 6.00000000mm
dotp = vnn * vin; // 152.40000000mm
dotp = vmm * vmm; // 5.00000000mm
dotp = vin * vin; // 3225.80000000mm
dotp = vmm * vin; // 101.60000000mm
dotp = vin * vmm; // 101.60000000mm vnn = [2.0, 2.0];
vmm = [1.0mm, 2.0mm];
vin = [2.0in, 1.0in];
dotp = vnn * vnn; // 8.00000000
dotp = vnn * vmm; // 2.15748031in
dotp = vnn * vin; // 6.00000000in
dotp = vmm * vmm; // 1.00620001in
dotp = vin * vin; // 5.00000000in
dotp = vmm * vin; // 2.07874016in
dotp = vin * vmm; // 2.07874016in vmm = [1.0mm, 2.0mm];
vin = [2.0in, 1.0in];
cosphi = (vmm * vin) / (length(vmm)*length(vin)); // CORRECT: 0.8 for both metric and imperial mode vmm = [1.0, 2.0mm]; // Note the lacking unit in first coordinate
vin = [2.0in, 1.0in];
cosphi = (vmm * vin) / (length(vmm)*length(vin)); // WRONG: 0.8 for metric and 0.92677230 for imperial mode vmm = normalize([1.0mm, 2.0mm]); // vmm = [0.44721360, 0.89442719]
vin = normalize([2.0in, 1.0in]); // vin = [0.89442719, 0.44721360]
cosphi = vmm * vin; // CORRECT: 0.8 for both metric and imperial mode i = 1;
v = [1, 10mm, 2.0in];
str = "Hello" + " " + "World!"; // "Hello World!"
str = "val=" + i; // "val=1"
str = "val=" + v; // "val=[1,10mm,2.00000000in]" var123 = [1, 2, 3, 4, 5];
feedrate(125.77mm);
_xx = 4.5mm;
yy = 50mil;
vec = [_xx, yy];
list = { vec, [_xx, yy], [1, 2, 3] };
a = vec[0]; /* a equals value of _xx (4.5mm) */
b = list[2]; /* b equals [1,2,3] */
val1 = val2 = val3 = 0; /* cascaded assignment */ const constinteger = 1234; /* Arbitrary constants */
const constfloat = 5.678;
const constvector = [1, -, 2];
const constlist = {[1], [2]}
constinteger = 7890; /* Error: cannot (re-)assign to constants */
/* Multiple declaration may be combined with comma as separator */
const FLAG_UP = 0x01, FLAG_DOWN = 0x02; /* Flags as constants */
const FLAG_LEFT = 0x04, FLAG_RIGHT = 0x08; if(!isvector(val)) {
error("val should be a vector");
return;
}
if(value >= 43) {
/* bla */
} elif(value < 0) {
/* Negative bla */
} elif(value == 5) {
/* the right bla */
} else {
/* None of the above bla */ list = { [0, 0], [1, 0], [1, 1], [0, 1] };
foreach(list; v) {
move(v);
}
foreach([1, 7, 3, 6, 4, 3, 1, 9, 0, 6, 4]; i) {
complex_sequenced_func(i);
} for(i = 0; i < 10; i++) {
do_something(i);
} while(complex_algo_check()) {
complex_algo_update(arg1, arg2);
} do {
res = complex_algo_update(arg1, arg2);
} while(res > limit); repeat(5) {
move_r([-, 1]); /* Incremental move in Y 5 times */
dwell(0.5); /* And wait 0.5s before continuing */
}
repeat(10; i) {
move([val * i / 10.0]);
...
}
function blabla() {
local foo, bar;
local var = 123, val = 0;
...
const localconstant = 999;
} function one()
{
return 1;
}
function nothing()
{
return;
}
message("one(): ", one()); // Prints "one(): 1"
message("nothing(): ", nothing()); // Prints "nothing(): <undef>" function func(valval, &valref)
{
valref *= 10;
valval *= 10;
}
i = 1;
j = 1;
func(i, j);
message("i=", i, ", j=", j); // Should print "i=1, j=10" function defargfunc(arg, defarg1 = 123, defarg2 = [1, sin(45.0deg)])
{
comment(arg, " ", defarg1, " ", defarg2);
}
defargfunc(1, 2, 3); /* Prints (1 2 3) */
defargfunc(1, 2); /* Prints (1 2 [1,0.70710678]) */
defargfunc(1); /* Prints (1 123 [1,0.70710678]) */ SAFEZ = [-, -, 10.0];
CUTZ = [-, -, -5.0];
HOME = [0, 0];
function do_stuff(vecs)
{
local v; /* Forces v to be local */
goto(vecs[-1]); /* Goto the last point */
move(CUTZ); /* Move to cutting depth */
foreach(vecs; v) { /* Iterate over the corners */
move(v);
}
goto(SAFEZ); /* Retract */
}
list = { [0,0], [1,0], [1,1], [0,1] };
do_stuff(list);
goto(HOME); include("other-file.gcmc")